<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="/themes/admin/css/font.css">
    <link rel="stylesheet" href="/themes/admin/css/xadmin.css">
</head>
<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="layui-tab layui-tab-brief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">导航菜单</li>
                            <li>置顶推荐</li>
                            <li>轮播图</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <div class="layui-collapse" style ="width:400px;border:0">
                                    {notempty name="navList"}
                                    {volist name="navList[0]" id="vo"}
                                    <div id="{$vo.nav_id}">
                                        <div class="layui-colla-item">
                                            <h2 class="layui-colla-title">{$vo.nav_title}</h2>
                                            <div class="layui-colla-content">
                                                <input type="text" value="{$vo.nav_title}"  class="layui-input">
                                                <input type="text" value="{$vo.url}"  class="layui-input">
                                                <input type="text" value="{$vo.order}"  class="layui-input">
                                                <button onclick="saveNav({$vo.nav_id},this)" class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top:10px;">
                                                    <i class="layui-icon">&#xe655;</i>保存
                                                </button>
                                                <button onclick="deleteNav({$vo.nav_id} ,this,0)" class="layui-btn layui-btn-danger layui-btn-sm" style="margin-top:10px;">
                                                    <i class="layui-icon">&#xe640;</i>删除
                                                </button>
                                            </div>
                                        </div>
                                        <!--子菜单开始-->
                                        {notempty name="navList[$vo.nav_id]"}
                                        {volist name="navList[$vo.nav_id]" id="v"}
                                        <div class="layui-colla-item" style="margin-bottom:10px;margin-left:30px;">
                                            <h2 class="layui-colla-title">{$v.nav_title}</h2>
                                            <div class="layui-colla-content">
                                                <input type="text" name="title" value="{$v.nav_title}"  class="layui-input">
                                                <input type="text" name="url" value="{$v.url}"  class="layui-input">
                                                <button onclick="saveNav({$v.nav_id},this)"  class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top:10px;">
                                                    <i class="layui-icon">&#xe655;</i>保存
                                                </button>
                                                <button onclick="deleteNav({$v.nav_id} ,this,{$v.parent_id})" class="layui-btn layui-btn-danger layui-btn-sm" style="margin-top:10px;">
                                                    <i class="layui-icon">&#xe640;</i>删除
                                                </button>
                                            </div>
                                        </div>
                                        {/volist}
                                        {/notempty}
                                        <!--子菜单结束-->
                                    </div>
                                    {/volist}
                                    {/notempty}
                                </div>
                                <div style="margin-top:10px;">
                                    <form class="layui-form" action="">
                                        <div class="layui-input-inline">
                                            <select id="add-nav-parent">
                                                <option value="">无父导航</option>
                                                {notempty name="navList"}
                                                {volist name="navList[0]" id="vo"}
                                                <option value="{$vo.nav_id}">{$vo.nav_title}</option>
                                                {/volist}
                                                {/notempty}
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <input type="text" id="add-nav-title" placeholder="导航名称" class="layui-input">
                                        </div>
                                        <div class="layui-input-inline">
                                            <input type="text" id="add-nav-url" placeholder="导航URL" class="layui-input">
                                        </div>
                                        <button type="button" onclick="addNav()" class="layui-btn">
                                            <i class="layui-icon">&#xe608;</i> 添加
                                        </button>
                                    </form>
                                </div>
                            </div>
                            <!--置顶推荐开始-->
                            <div class="layui-tab-item">
                                <form class="layui-form" action="">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">置顶文章</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="articleId" required value="{$topArticle.value}" autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">(请输入文章Id,用英文半角逗号隔开)</div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="btn-top-article">保存</button>
                                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <!--置顶推荐结束-->
                            <!--轮播图开始-->
                            <div class="layui-tab-item">
                                <form class="layui-form" action="">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">轮播文章</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="articleId" required value="{$carousel.value}" autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">(请输入文章Id,用英文半角逗号隔开)</div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="carousel">保存</button>
                                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                        </div>
                                    </div>
                                </form>

                            </div>
                            <!--轮播图结束-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/themes/admin/lib/layui/layui.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="/themes/admin/js/xadmin.js"></script>
<script>
    layui.use('element');
    layui.use('layer');
    layui.use('form');
    //轮播图文章设置
    var topArticle = "{$topArticle['extend']}";
    if(topArticle == 1){
        $("#topSwitch").attr("checked","checked");
    }
    layui.use('form', function(){
        var form = layui.form;
        form.on('submit(carousel)', function(data){
            var value = data.field.articleId;
            $.ajax({
                type:"post",
                data:"value="+value,
                url:"/admin/system/carousel",
                success:function(e){
                    if(e.code == 1){
                        layer.msg(e.msg,{icon:1});
                    }else{
                        layer.msg(e.msg);
                    }
                }
            });
            return false;
        });
    });
    //置顶文章设置
    var topArticle = "{$topArticle['extend']}";
    if(topArticle == 1){
        $("#topSwitch").attr("checked","checked");
    }
    layui.use('form', function(){
        var form = layui.form;
        form.on('submit(btn-top-article)', function(data){
            var value = data.field.articleId;
            $.ajax({
                type:"post",
                data:"value = "+value,
                url:"/admin/system/topArticle",
                success:function(e){
                    if(e.code == 1){
                        layer.msg(e.msg,{icon:1});
                    }else{
                        layer.msg(e.msg);
                    }
                }
            });
            return false;
        });
    });
    //删除导航
    function deleteNav(navId,obj,parentId){
        if(parentId == 0){
            var ts = "该导航是父级导航，将一起删除其子导航？"
        }else{
            var ts = "确定删除？";
        }
        layer.msg(ts , {
            time: 0 //不自动关闭
            ,btn: ['删除', '取消']
            ,yes: function(index){
                $.ajax({
                    type:"post",
                    data:"navId="+navId,
                    url:"/admin/system/deleteNav",
                    success:function(e){
                        if(e.code == 1){
                            if(parentId == 0){
                                self.location.reload();
                                $("#" +navId).remove();
                            }else{
                                $(obj).parents(".layui-colla-item").remove();
                            }
                            layer.msg(e.msg,{icon:1});
                        }else{
                            layer.msg(e.msg);
                        }
                    }
                });
                layer.close(index);
            }
        });
    }

    //保存导航
    function saveNav(navId ,obj){
        var linkTitle = $(obj).parent("div").find("input").eq(0).val();
        var linkUrl = $(obj).parent("div").find("input").eq(1).val();
        var linkOrder = $(obj).parent("div").find("input").eq(2).val();
        $.ajax({
            type:"post",
            data:{
                nav_id:navId,
                nav_title:linkTitle,
                url:linkUrl,
                order:linkOrder
            },
            url:"/admin/system/saveNav",
            success:function(e){
                if(e.code == 1){
                    layer.msg(e.msg,{icon:1});
                    location.reload();
                }else{
                    layer.msg(e.msg,{icon:2});
                }
            }
        });
    }

    //添加导航
    function addNav(){
        var navTitle = $("#add-nav-title").val();
        var navUrl = $("#add-nav-url").val();
        var navParent = $("#add-nav-parent option:selected").val();
        $.ajax({
            type:"post",
            data:"navTitle=" + navTitle + "&navUrl="+ navUrl + "&navParent=" +navParent,
            url:"/admin/system/addNav",
            success:function(e){
                if(e.code == 1){
                    self.location.reload();
                }else{
                    layer.msg(e.msg);
                }
            }
        });
    }
    //添加友情链接
    function addLink(obj){
        var linkTitle = $("#link-title").val();
        var linkUrl = $("#link-url").val();
        $.ajax({
            type:"post",
            data:"linkTitle=" + linkTitle + "&linkUrl="+ linkUrl,
            url:"/admin/system/addLink",
            success:function(e){
                if(e.code == 1){
                    $(obj).parents("tr").before('<tr><td>'+e.data.id+'</td><td><input type="text"  value="'+e.data.title+'" class="layui-input"></td><td><input type="text"  value="'+e.data.url+'" class="layui-input"></td><td><button onclick="editLink('+e.data.id+',this)" class="layui-btn layui-btn-normal">修改</button><button onclick="deleteLink('+e.data.id+',this)" class="layui-btn layui-btn-danger">删除</button></td></tr>')
                    layer.msg(e.msg,{icon:1});
                }else{
                    layer.msg(e.msg);
                }
            }
        });
    }
    //修改友情链接
    function editLink(linkId,obj){
        var linkTitle = $(obj).parents('tr').find('input').eq(0).val();
        var linkUrl = $(obj).parents('tr').find('input').eq(1).val();
        $.ajax({
            type:"post",
            data:"linkId="+linkId + "&linkTitle=" + linkTitle + "&linkUrl="+ linkUrl,
            url:"/admin/system/editLink",
            success:function(e){
                if(e.code == 1){
                    layer.msg(e.msg,{icon:1});
                }else{
                    layer.msg(e.msg);
                }
            }
        });
    }
    //删除友情链接
    function deleteLink(linkId,obj)
    {
        layer.msg("确定删除？" , {
            time: 0 //不自动关闭
            ,btn: ['删除', '取消']
            ,yes: function(index){
                $.ajax({
                    type:"post",
                    data:"linkId="+linkId,
                    url:"/admin/system/deleteLink",
                    success:function(e){
                        if(e.code == 1){
                            $(obj).parents('tr').remove();
                            layer.msg(e.msg,{icon:1});
                        }else{
                            layer.msg(e.msg);
                        }
                    }
                });
                layer.close(index);
            }
        });
    }
</script>
</body>
</html>